package core.net;

import core.common.Utils;
import core.pojos.DriveDir;
import core.pojos.DriveItem;
import core.pojos.DropboxDir;
import core.pojos.OneDriveDir;
import core.pojos.OneDriveItem;
import java.io.IOException;
import org.codehaus.jackson.map.ObjectMapper;

/**
 *
 * @author royal
 */
public class Json {

    public static DropboxDir ToDropboxDir(String json) throws IOException {
        if (!Utils.isNullOrEmptyString(json)) {
            ObjectMapper mapper = new ObjectMapper();
            DropboxDir dir = mapper.readValue(json, DropboxDir.class);
            return dir;
        } else {
            return new DropboxDir();
        }

    }

    public static DriveDir ToDriveDir(String json) throws IOException {
        if (!Utils.isNullOrEmptyString(json)) {
            ObjectMapper mapper = new ObjectMapper();
            DriveDir dir = mapper.readValue(json, DriveDir.class);
            return dir;
        } else {
            return new DriveDir();
        }
    }

    public static DriveItem ToDriveItemList(String json) throws IOException {
        ObjectMapper mapper = new ObjectMapper();
        DriveItem item = mapper.readValue(json, DriveItem.class);
        return item;
    }

    public static OneDriveDir ToOneDriveDir(String json) throws IOException {
        if (!Utils.isNullOrEmptyString(json)) {
            ObjectMapper mapper = new ObjectMapper();
            OneDriveDir dir = mapper.readValue(json, OneDriveDir.class);
            return dir;
        }
        return new OneDriveDir();
    }

    public static OneDriveItem ToOneDriveItemList(String json) throws IOException {
        ObjectMapper mapper = new ObjectMapper();
        OneDriveItem item = mapper.readValue(json, OneDriveItem.class);
        return item;
    }

}
